/****************************************************
 * @class MyOwnDocument
 * @extends Ext.grid.GridPanel
 ***************************************************/
	MyOwnDocument = Ext.extend(Ext.grid.GridPanel,{
		_cur_user_id: null,
		_unfinished: null,
		condition: null,
		store: null,
		cm: null,
		searchField: null,
		constructor: function(config){
			Ext.apply(this,config);
			
			this.condition = {owner: this._cur_user_id, onhand: this._unfinished, limit: 50};
			
			this.store = new Ext.data.Store({
			    baseParams: this.condition,   
				proxy: new Ext.data.HttpProxy({
					method: 'POST',
					url: window.basePath + '/owner.htm?method=todo'
				}),
				reader: new Ext.data.JsonReader({
					totalProperty: 'totalProperty',
					root: 'root',
					id: 'doc_id'
				},[
					{name: 'doc_id'},
					{name: 'mastIns_id'},
					{name: 'docName'},
					{name: 'dateOfCreate'},
					{name: 'projectName'},
					{name: 'deriveName'},
					{name: 'size'},
					{name: 'owner'},
					{name: 'stage'},
					{name: 'status'}
				])
			});
			this.cm = new Ext.grid.ColumnModel([
				new Ext.grid.RowNumberer(),
		        {
					header: "专案",
					dataIndex: 'projectName',
					hidden: false,
					sortable: true,
					width: 80
		        },{
					header: "衍生计划名",
					dataIndex: 'deriveName',
					sortable: true,
					width: 70
		        },{
					header: "现行阶段",
					dataIndex: 'stage',
					align: 'left',
					sortable: true,
					width: 80
	        	},{
					header: "文件名称",
					dataIndex: 'docName',
					sortable: true,
					width: 180
		        },{
					header: "负责人员",
					dataIndex: 'owner',
					align: 'left',
					sortable: true,
					width: 120
	        	},{
					header: "起案日期",
					dataIndex: 'dateOfCreate',
					sortable: false,
					width: 120
		        },{
					header: "完成状况",
					dataIndex: 'status',
					align: 'left',
					sortable: true,
					width: 120,
					renderer: function(v,m){
						if(v=="[100] Unstarted") m.css = 'x-grid-status-ux-gray';
						else if(v=="[500] On-Going") m.css = 'x-grid-status-ux-yellow';
						else if(v=="[800] Delayed") m.css = 'x-grid-status-ux-red';
						else if(v=="[900] Released"||v=="[910] Closed") m.css = 'x-grid-status-ux-green';
						return v;
					}
	        	}]);
	        //this.store.load();
			this.searchField = new Ext.ux.form.SearchField({store: this.store, width:200});
			
			MyOwnDocument.superclass.constructor.call(this, {
			    loadMask: {msg:'Loading...'},
			    viewConfig: {forceFit: true},
				region: 'center',
				border: false,
				height: 500,
				layout: 'fit',
				split: true,
				cls: 'x-rb',
				ds: this.store,
				sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
				cm: this.cm,
				trackMouseOver: false,
				tbar: ["文档查询：",this.searchField],
				bbar: new Ext.PagingToolbar({
					pageSize: 50,
					store: this.store,
					displayInfo: true,
					displayMsg: '显示第 {0}~{1} 条，共 {2} 条记录',
					emptyMsg: "没有记录",
					refreshText: '刷新',
					beforePageText: '第',
					afterPageText: '页，共 {0} 页',
					firstText: '第一页',
					prevText: '前一页',
					nextText: '后一页',
					lastText: '最后一页'
				})
			});
			
			this.on('rowdblclick', function(grid, rowIndex, e){
				var record = grid.getSelectionModel().getSelected();
				var docName = record.get("docName");
				var mastInsId = record.get("mastIns_id");
				
				if(mastInsId == 0)
				{
					Ext.Msg.alert("信息","["+ docName + "] 无法开启，请联系管理员。");
				}
				//else window.open("AutoCreate.jsp?mast_id="+mastInsId+"&tmpl_id="+tmplId);
				else window.open(window.basePath + "/form.htm?method=show&mast_id=" + mastInsId);
			});
			
		},
		load: function(con){
			this.condition.limit = 50;
			this.condition.owner = con;
			this.store.load();
		}
	});